package departmentenum

import (
	"yunj/pkg/yunj/core/enum"
)

// 定义部门类型常量
const (
	// 公司
	TYPE_COMPANY uint8 = 11

	// 子公司
	TYPE_SUBSIDIARY uint8 = 22

	// 部门
	TYPE_DEPARTMENT uint8 = 33

	// 小组
	TYPE_TEAM uint8 = 44
)

// 部门类型
// 实现EnumInerface接口
type Type struct {
	enum.Enum[uint8]
}

func (e *Type) AllConstAttrs() map[uint8]map[string]any {
	return map[uint8]map[string]any{
		TYPE_COMPANY: {
			"desc":  "公司",
			"sort":  1,
			"color": "#16b777",
		},
		TYPE_SUBSIDIARY: {
			"desc":  "子公司",
			"sort":  2,
			"color": "#16baaa",
		},
		TYPE_DEPARTMENT: {
			"desc":  "部门",
			"sort":  3,
			"color": "#1e9fff",
		},
		TYPE_TEAM: {
			"desc":  "小组",
			"sort":  4,
			"color": "#2f363c",
		},
	}
}

// instanceCache 存储已经创建的实例
var typeInstanceCache = make(map[uint8]*Type)

// 根据value获取枚举
func TypeByValue(value uint8) *Type {
	if instance, exists := typeInstanceCache[value]; exists {
		return instance
	}
	e := &Type{}
	enum.SetEnumInstance(&e.Enum, e, value)
	typeInstanceCache[value] = e
	return e
}

var TypeEnum *Type = func() *Type {
	e := &Type{}
	enum.SetEnumInstance(&e.Enum, e)
	return e
}()
